"""Build DAOS client"""

LIBDAOS_SRC = ['agent.c', 'array.c', 'container.c', 'event.c', 'init.c', 'job.c', 'kv.c', 'mgmt.c',
               'object.c', 'pool.c', 'rpc.c', 'task.c', 'tx.c', 'pipeline.c', 'metrics.c']


def scons():
    """Execute build"""
    Import('env', 'API_VERSION', 'prereqs', 'libdaos_tgts')

    env.d_add_build_rpath()
    env.AppendUnique(LIBPATH=[Dir('.')])
    denv = env.Clone()
    denv.require('protobufc')
    libdaos_tgts[:0] = denv.SharedObject(LIBDAOS_SRC)

    if prereqs.client_requested():
        libdaos = env.d_library('daos', libdaos_tgts, SHLIBVERSION=API_VERSION,
                                LIBS=['daos_common'])
        if hasattr(env, 'InstallVersionedLib'):
            env.InstallVersionedLib('$PREFIX/lib64/', libdaos, SHLIBVERSION=API_VERSION)
        else:
            env.Install('$PREFIX/lib64/', libdaos)

    if prereqs.test_requested():
        SConscript('tests/SConscript', exports='denv')


if __name__ == "SCons.Script":
    scons()
